home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-05 / drivers2.zip / PKTTRAF.ASM < prev    next >
Assembly Source File  |  1992-01-23  |  10KB  |  535 lines

  1. version    equ    0
  2.  
  3. ;History:5,1
  4.  
  5. ;  Copyright 1990-1992, Russell Nelson, Crynwr Software
  6.  
  7. ;   This program is free software; you can redistribute it and/or modify
  8. ;   it under the terms of the GNU General Public License as published by
  9. ;   the Free Software Foundation, version 1.
  10. ;
  11. ;   This program is distributed in the hope that it will be useful,
  12. ;   but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. ;   GNU General Public License for more details.
  15. ;
  16. ;   You should have received a copy of the GNU General Public License
  17. ;   along with this program; if not, write to the Free Software
  18. ;   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20.     include    defs.asm
  21.  
  22. BS    equ    8
  23.  
  24. code    segment word public
  25.     assume    cs:code, ds:code
  26.  
  27.     org    80h
  28. phd_dioa    label    byte
  29.  
  30.     org    100h
  31. start:
  32.     jmp    start_1
  33.  
  34. copyleft_msg    label    byte
  35.  db "Packet traffic version ",'0'+(majver / 10),'0'+(majver mod 10),".",'0'+version," copyright 1990, Russell Nelson.",CR,LF
  36.  db "This program is free software; see the file COPYING for details.",CR,LF
  37.  db "NO WARRANTY; see the file COPYING for details.",CR,LF
  38. crlf_msg    db    CR,LF,'$'
  39.  
  40. int_pkt    macro
  41.     pushf
  42.     cli
  43.     call    their_isr
  44.     endm
  45.  
  46. their_isr    dd    ?
  47. packet_int_no    db    ?,?,?,?
  48. handle        dw    ?
  49.  
  50. signature    db    'PKT DRVR',0
  51. signature_len    equ    $-signature
  52. no_signature_msg    db    "No packet driver at that address",'$'
  53. usage_msg    db    "usage: pkttraf <packet_int_no>",'$'
  54. waiting_msg    label    byte
  55. db "Graphically display network traffic.  The Ethernet address of the",CR,LF
  56. db "highlighted node is shown in the lower right corner.  The space key will",CR,LF
  57. db "advance counter-clockwise, backspace will retreat clockwise, escape will",CR,LF
  58. db "exit.",CR,LF
  59. db CR,LF
  60. db "Press any key to continue.",CR,LF,'$'
  61.  
  62.     include    pixel.asm
  63.     include    line.asm
  64.  
  65. MAX_NODES    equ    20
  66.  
  67. xy_pairs    label    word
  68.     dw    100,198
  69.     dw    130,193
  70.     dw    157,179
  71.     dw    179,157
  72.     dw    193,130
  73.     dw    198,100
  74.     dw    193,69
  75.     dw    179,42
  76.     dw    157,20
  77.     dw    130,6
  78.     dw    100,2
  79.     dw    69,6
  80.     dw    42,20
  81.     dw    20,42
  82.     dw    6,69
  83.     dw    2,99
  84.     dw    6,130
  85.     dw    20,157
  86.     dw    42,179
  87.     dw    69,193
  88.  
  89. eaddr_list    db    EADDR_LEN * MAX_NODES dup(0)
  90. eaddr_end    dw    eaddr_list
  91.  
  92. traffic_list    db    MAX_NODES * MAX_NODES dup(0)
  93. traffic_scale    db    0
  94.  
  95. cursor    db    0            ;between 0 and MAX_NODES-1
  96.  
  97. usage_error:
  98.     mov    dx,offset usage_msg
  99. error:
  100.     mov    ah,9
  101.     int    21h
  102.     int    20h
  103.  
  104. start_1:
  105.     mov    dx,offset copyleft_msg
  106.     mov    ah,9
  107.     int    21h
  108.  
  109.     mov    si,offset phd_dioa+1
  110.     cmp    byte ptr [si],CR    ;end of line?
  111.     je    usage_error
  112.  
  113.     mov    di,offset packet_int_no
  114.     call    get_number
  115.  
  116.     mov    ah,35h            ;get their packet interrupt.
  117.     mov    al,packet_int_no
  118.     int    21h
  119.     mov    their_isr.offs,bx
  120.     mov    their_isr.segm,es
  121.  
  122.     lea    di,3[bx]
  123.     mov    si,offset signature
  124.     mov    cx,signature_len
  125.     repe    cmpsb
  126.     mov    dx,offset no_signature_msg
  127.     jne    error
  128.  
  129.     push    ds
  130.     mov    ax,1ffh            ;driver_info
  131.     int_pkt
  132.     pop    ds
  133.     call    fatal_error
  134.  
  135.     mov    ah,2            ;access all packets.
  136.     mov    al,ch            ;their class from driver_info().
  137.     mov    bx,dx            ;their type from driver_info().
  138.     mov    dl,cl            ;their number from driver_info().
  139.     mov    cx,0            ;type length of zero.
  140.     push    cs            ;es:di -> our receiver.
  141.     pop    es
  142.     mov    di,offset our_recv
  143.     int_pkt
  144.     call    fatal_error
  145.     mov    handle,ax
  146.  
  147.     mov    ah,20            ;set receive mode.
  148.     mov    bx,handle
  149.     mov    cx,6            ;receive all packets.
  150.     int_pkt
  151.     call    fatal_error
  152.  
  153.     mov    dx,offset waiting_msg
  154.     mov    ah,9
  155.     int    21h
  156.  
  157.     mov    ah,0            ;fetch the key.
  158.     int    16h
  159.  
  160.     call    init_vid
  161.  
  162. wait_for_key:
  163.     call    draw_eaddr
  164.  
  165.     cmp    traffic_scale,0        ;do we need to rescale?
  166.     je    no_rescale
  167.     mov    si,offset traffic_list
  168.     mov    cx,MAX_NODES*MAX_NODES
  169. rescale:
  170.     shr    byte ptr [si],1        ;divide all the traffic in half.
  171.     inc    si
  172.     loop    rescale
  173.     mov    traffic_scale,0
  174. no_rescale:
  175.  
  176.     xor    bx,bx
  177.     mov    al,4
  178.     mul    cursor
  179. write_dots:
  180.     mov    cx,xy_pairs[bx].offs    ;get the X and Y coordinate.
  181.     mov    dx,xy_pairs[bx].segm
  182.     push    ax
  183.     push    bx
  184.     cmp    ax,bx            ;at the cursor?
  185.     mov    al,60h            ;use a dim dot.
  186.     jne    write_dots_1
  187.     mov    al,0ffh            ;use a bright dot.
  188. write_dots_1:
  189.     call    draw_dot
  190.     pop    bx
  191.     pop    ax
  192.     add    bx,4
  193.     cmp    bx,MAX_NODES*4
  194.     jb    write_dots
  195.  
  196.   if 0
  197. ;draw the cursor.
  198.     mov    cx,xy_pairs[bx].offs    ;get the X and Y coordinate.
  199.     mov    dx,xy_pairs[bx].segm
  200.     call    draw_bullet
  201.   endif
  202.  
  203.     mov    si,offset traffic_list
  204.     mov    dh,0
  205. write_nodes:
  206.     mov    dl,dh
  207.     inc    dl
  208. write_nodes_1:
  209.   if 0
  210.     mov    al,MAX_NODES
  211.     mul    dh
  212.     add    al,dl
  213.     adc    ah,0
  214.   endif
  215.  
  216.     lodsb
  217.     push    si
  218.     call    write_one_node
  219.     pop    si
  220.     inc    dl
  221.     cmp    dl,MAX_NODES
  222.     jb    write_nodes_1
  223.  
  224.     mov    ah,1            ;check for any key.
  225.     int    16h
  226.     jne    test_for_key        ;got a key - go get it.
  227.  
  228.     inc    dh
  229.     cmp    dh,MAX_NODES - 1
  230.     jb    write_nodes
  231.  
  232. test_for_key:
  233.     mov    ah,1            ;check for any key.
  234.     int    16h
  235.     je    wait_for_key        ;no key -- keep waiting.
  236.  
  237.     mov    ah,0            ;fetch the key.
  238.     int    16h
  239.  
  240.     cmp    al,1bh            ;Escape?
  241.     je    all_done
  242.     cmp    al,'q'            ;Quit?
  243.     je    all_done
  244.     cmp    al,BS
  245.     je    backspace
  246.     cmp    al,' '
  247.     jne    test_for_key
  248.  
  249.     inc    cursor            ;move over by one.
  250.     cmp    cursor,MAX_NODES    ;should we wrap around?
  251.     jb    test_for_key
  252.     mov    cursor,0
  253.     jmp    test_for_key
  254.  
  255. backspace:
  256.     dec    cursor            ;move over by one.
  257.     cmp    cursor,-1        ;should we wrap around?
  258.     jne    test_for_key
  259.     mov    cursor,MAX_NODES-1
  260.     jmp    test_for_key
  261.  
  262.  
  263. all_done:
  264.  
  265.     call    uninit_vid
  266.  
  267.     mov    ah,20            ;set receive mode.
  268.     mov    bx,handle
  269.     mov    cx,3            ;receive ours + broadcasts.
  270.     int_pkt
  271.     call    fatal_error
  272.  
  273.     mov    ah,3
  274.     mov    bx,handle
  275.     int_pkt
  276.     call    fatal_error
  277.  
  278.     int    20h
  279.  
  280.  
  281. write_one_node:
  282. ;enter with dh, dl = a pair of nodes, al = amount of traffic.
  283. ;preserve dx.
  284.     push    dx
  285.  
  286.     mov    bl,dh
  287.     xor    bh,bh
  288.     shl    bx,1
  289.     shl    bx,1
  290.     mov    si,xy_pairs[bx].offs    ;get the X and Y coordinate.
  291.     mov    di,xy_pairs[bx].segm
  292.  
  293.     mov    bl,dl
  294.     xor    bh,bh
  295.     shl    bx,1
  296.     shl    bx,1
  297.     mov    cx,xy_pairs[bx].offs    ;get the X and Y coordinate.
  298.     mov    dx,xy_pairs[bx].segm
  299.  
  300.     call    line
  301.     pop    dx
  302.     ret
  303.  
  304.  
  305. dot_color    db    ?
  306.  
  307. draw_dot:
  308. ;enter with cx, dx = point to draw a dot around, al = color of dot.
  309. ;  ***
  310. ; *   *
  311. ; * X *
  312. ; *   *
  313. ;  ***
  314.     mov    dot_color,al
  315.     call    open_vid
  316.     call    move_left
  317.     call    move_left
  318.     call    move_up
  319.     mov    al,dot_color
  320.     call    set_bit
  321.     call    move_down
  322.     mov    al,dot_color
  323.     call    set_bit
  324.     call    move_down
  325.     mov    al,dot_color
  326.     call    set_bit
  327.     call    move_right
  328.     call    move_down
  329.     mov    al,dot_color
  330.     call    set_bit
  331.     call    move_right
  332.     mov    al,dot_color
  333.     call    set_bit
  334.     call    move_right
  335.     mov    al,dot_color
  336.     call    set_bit
  337.     call    move_right
  338.     call    move_right
  339.     call    move_up
  340.     mov    al,dot_color
  341.     call    set_bit
  342.     call    move_up
  343.     mov    al,dot_color
  344.     call    set_bit
  345.     call    move_up
  346.     mov    al,dot_color
  347.     call    set_bit
  348.     call    move_up
  349.     call    move_left
  350.     mov    al,dot_color
  351.     call    set_bit
  352.     call    move_left
  353.     mov    al,dot_color
  354.     call    set_bit
  355.     call    move_left
  356.     mov    al,dot_color
  357.     call    set_bit
  358.     call    close_vid
  359.     ret
  360.  
  361.  
  362. draw_bullet:
  363. ;enter with cx, dx = point to draw a dot around.
  364. ; HGF
  365. ; A E
  366. ; BCD
  367.     call    open_vid
  368.     call    move_left
  369.     mov    al,0ffh            ;A
  370.     call    set_bit
  371.     call    move_down
  372.     mov    al,0ffh            ;B
  373.     call    set_bit
  374.     call    move_right
  375.     mov    al,0ffh            ;C
  376.     call    set_bit
  377.     call    move_right
  378.     mov    al,0ffh            ;D
  379.     call    set_bit
  380.     call    move_up
  381.     mov    al,0ffh            ;E
  382.     call    set_bit
  383.     call    move_up
  384.     mov    al,0ffh            ;F
  385.     call    set_bit
  386.     call    move_left
  387.     mov    al,0ffh            ;G
  388.     call    set_bit
  389.     call    move_left
  390.     mov    al,0ffh            ;H
  391.     call    set_bit
  392.     call    close_vid
  393.     ret
  394.  
  395. draw_eaddr:
  396.     mov    ah,2            ;set cursor position
  397.     mov    bh,0
  398.     mov    dh,24
  399.     mov    dl,40-EADDR_LEN*3
  400.     int    10h
  401.  
  402.     mov    al,cursor
  403.     mov    ah,EADDR_LEN
  404.     mul    ah
  405.     add    ax,offset eaddr_list
  406.     mov    si,ax
  407.     call    print_ether_addr
  408.     ret
  409.  
  410.  
  411. our_recv:
  412.     or    ax,ax            ;first or second call?
  413.     jne    our_recv_1        ;second -- bump the packet flag.
  414.     push    cs
  415.     pop    es
  416.     mov    di,offset our_buffer
  417.     db    0cbh            ;masm 4.0 doesn't grok "retf"
  418. our_recv_1:
  419.     push    ax
  420.     push    bx
  421.     push    cx
  422.     push    dx
  423.     push    si
  424.     push    di
  425.     push    bp
  426.     push    ds
  427.     push    es
  428.  
  429.     cld
  430.  
  431.     mov    ax,cs
  432.     mov    ds,ax
  433.     mov    es,ax
  434.  
  435.     call    receive
  436.  
  437.     pop    es
  438.     pop    ds
  439.     pop    bp
  440.     pop    di
  441.     pop    si
  442.     pop    dx
  443.     pop    cx
  444.     pop    bx
  445.     pop    ax
  446.     db    0cbh            ;masm 4.0 doesn't grok "retf"
  447.  
  448. receive:
  449.     mov    si,offset our_buffer    ;get the "to" address.
  450.     call    find_address
  451.     jc    receive_2        ;too many!
  452.     push    ax
  453.     mov    si,offset our_buffer+EADDR_LEN    ;get the "from" address.
  454.     call    find_address
  455.     pop    bx
  456.     jc    receive_2        ;too many!
  457.     mul    bl
  458.     mov    bx,ax
  459.     cmp    bx,MAX_NODES * MAX_NODES
  460.     jae    receive_2
  461.     cmp    traffic_list[bx],255    ;at the maximum already?
  462.     je    receive_1
  463.     inc    traffic_list[bx]    ;increase the amount of traffic.
  464. receive_2:
  465.     ret
  466. receive_1:
  467.     inc    traffic_scale
  468.     ret
  469.  
  470.  
  471. find_address:
  472. ;enter with si -> incoming Ethernet address.
  473. ;exit with nc, al = node number, or cy if we can't remember this one.
  474.     mov    cx,MAX_NODES
  475.     mov    di,offset eaddr_list
  476. find_address_1:
  477.     cmp    di,eaddr_end        ;did we hit the end?
  478.     jae    find_address_5
  479.     cmpsw
  480.     jne    find_address_2
  481.     cmpsw
  482.     jne    find_address_3
  483.     cmpsw
  484.     jne    find_address_4
  485.     jmp    short find_address_6
  486. find_address_2:
  487.     add    si,2            ;increment by another two bytes.
  488.     add    di,2
  489. find_address_3:
  490.     add    si,2            ;increment by another two bytes.
  491.     add    di,2
  492. find_address_4:
  493.     add    si,-6            ;back si up to the beginning.
  494.     loop    find_address_1        ;or run out of slots?
  495.     stc
  496.     ret
  497. find_address_5:
  498.     movsw                ;okay, remember it here.
  499.     movsw
  500.     movsw
  501.     mov    eaddr_end,di
  502. find_address_6:
  503.     mov    al,MAX_NODES
  504.     sub    al,cl
  505.     clc
  506.     ret
  507.  
  508.  
  509.     include    printea.asm
  510.     include    pkterr.asm
  511.     include    getnum.asm
  512.     include    getdig.asm
  513.     include    skipblk.asm
  514.     include    digout.asm
  515.  
  516. chrout:
  517.     push    ax            ;print the char in al.
  518.     push    bx
  519.     push    bp
  520.     mov    ah,0eh
  521.     mov    bh,0
  522.     mov    bl,0ffh
  523.     int    10h
  524.     pop    bp
  525.     pop    bx
  526.     pop    ax
  527.     ret
  528.  
  529.  
  530. our_buffer    label    byte
  531.  
  532. code    ends
  533.  
  534.     end    start
  535.